<?php
/**
 * Created by Zhy
 * User: Zhy
 * Date: 2023/1/9
 * Time: 16:15
 */

namespace app\admin\controller;

use think\Db;
use think\Request;

class Giftbagrule extends Base
{
    /**
     * 礼包规则
     * @return mixed|\think\response\Json
     * @throws \think\Exception
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     * @throws \think\exception\PDOException
     */
    public function index(){
        if(Request::instance()->isPost()){
            $rule_image = input('rule_image');
            $rule_content = input('rule_content');

            $update = [
                'rule_image' => $rule_image,
                'rule_content' => $rule_content,
                'rule_update_time' => date('Y-m-d H:i:s')
            ];
            $res = Db::table('up_bo_giftbag_rule')->where('rule_id', 1)->update($update);
            if($res){
                return json(['code' => 200, 'msg' => '保存成功']);
            }else{
                return json(['code' => 100, 'msg' => '保存失败']);
            }
        }
        $data = Db::table('up_bo_giftbag_rule')->where('rule_id', 1)->field('rule_image, rule_content')->find();
        $this->assign('data', $data);
        return $this->fetch('giftbagrule/index');
    }

}